﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Public;

namespace DAL
{
    public class VatTu_DAL
    {
        Connection conn = new Connection();
        #region"Lấy danh sách vật tư, hàng hóa"
        public DataTable LayDSVatTu()
        {
            return conn.LoadData("Select * from VATTU");
        }

        #endregion
        #region "Thêm Vật tư, Hàng hóa"
        public int ThemVatTuHangHoa(VatTu_PB vt_pb)
        {
            int nparamater = 9;
            string[] name = new string[nparamater];
            object[] value = new object[nparamater];
            name[0] = "@mavattu"; value[0] = VatTu_PB.MaVatTu;
            name[1] = "@tenvattu"; value[1] = VatTu_PB.TenVatTu;
            name[2] = "@tinhchat"; value[2] = VatTu_PB.TinhChat;
            name[3] = "@nhom"; value[3] = VatTu_PB.Nhom;
            name[4] = "@mota"; value[4] = VatTu_PB.MoTa;
            name[5] = "@donvitinh"; value[5] = VatTu_PB.DonViTinh;
            name[6] = "@thoihanbh"; value[6] = VatTu_PB.ThoiHanBH;
            name[7] = "@soluong"; value[7] = VatTu_PB.SoLuong;
            name[8] = "@nguongoc"; value[8] = VatTu_PB.NguonGoc;

            string sql = "insert into VATTU values (@mavattu,@tenvattu,@tinhchat,@nhom,@mota,@donvitinh,@thoihanbh,@soluong,@nguongoc)";
            return conn.Update(sql, name, value, nparamater);
        }

        #endregion

        #region "Sua Vat tu, Hang hoa"

        public int SuaVatTu(VatTu_PB vt_pb)
        {
            int nparameter = 9;
            string[] name = new string[nparameter];
            object[] value = new object[nparameter];
            name[0] = "@mavattu"; value[0] = VatTu_PB.MaVatTu;
            name[1] = "@tenvattu"; value[1] = VatTu_PB.TenVatTu;
            name[2] = "@tinhchat"; value[2] = VatTu_PB.TinhChat;
            name[3] = "@nhom"; value[3] = VatTu_PB.Nhom;
            name[4] = "@mota"; value[4] = VatTu_PB.MoTa;
            name[5] = "@donvitinh"; value[5] = VatTu_PB.DonViTinh;
            name[6] = "@thoihanbh"; value[6] = VatTu_PB.ThoiHanBH;
            name[7] = "@soluong"; value[7] = VatTu_PB.SoLuong;
            name[8] = "@nguongoc"; value[8] = VatTu_PB.NguonGoc;
            string sql = "update VATTU set TENVATTU = @tenvattu,TINHCHAT=@tinhchat, NHOM = @nhom,MOTA =  @mota, DONVITINH = @donvitinh,THOIHANBH = @thoihanbh, SOLUONG  = @soluong,NGUONGOC  = @nguongoc where MAVATTU=@mavattu";
            return conn.Update(sql, name, value, nparameter);
        }
        #endregion



        #region "Xóa Vật tư, Hàng hóa"
        public int XoaVatTu(VatTu_PB vt_pb)
        {
            int nparamater = 9;
            string[] name = new string[nparamater];
            object[] value = new object[nparamater];
            name[0] = "@mavattu"; value[0] = VatTu_PB.MaVatTu;
            name[1] = "@tenvattu"; value[1] = VatTu_PB.TenVatTu;
            name[2] = "@tinhchat"; value[2] = VatTu_PB.TinhChat;
            name[3] = "@nhom"; value[3] = VatTu_PB.Nhom;
            name[4] = "@mota"; value[4] = VatTu_PB.MoTa;
            name[5] = "@donvitinh"; value[5] = VatTu_PB.DonViTinh;
            name[6] = "@thoihanbh"; value[6] = VatTu_PB.ThoiHanBH;
            name[7] = "@soluong"; value[7] = VatTu_PB.SoLuong;
            name[8] = "@nguongoc"; value[8] = VatTu_PB.NguonGoc;

            string sql = "delete from VATTU where MAVATTU=@mavattu";
            return conn.Update(sql, name, value, nparamater);
        }

        #endregion
    }
}
